<?
/**
 *订单记录类. C 端使用，如云顶，二级域名
 *查询订单详情和处理订单的相关操作.
 */
class OrderRecord_c extends OrderRecord{
	
    /**
	 *未支付订单支付函数.
	 *将处理订单的分润数据，并跳的支付宝支付
	 */
	public function alipay_c($pay=array()){
    
        $script_uri = substr($_SERVER['SCRIPT_URI'],0,strrpos($_SERVER['SCRIPT_URI'],'/'));
        $payArr = array(
            'pay_url'    => '',
            'show_url'   => $script_uri.'/gdetail.html', // 商品展示地址
            'return_url' => $script_uri.'/gpay_suc.html',// 支付成功显示页面
            'notify_url' => $script_uri.'/alipay/ali_order/notify_url_dev.php',// 回调地址
        );
        $payArr = array_merge($payArr,$pay);
		$mid = $_SESSION['sid'];
		$orderInfo=$this->info();
		$orderid=(string)$orderInfo['mainOrder']->UUordernum;
		$title=($orderInfo['mainOrder']->UUltitle).($orderInfo['mainOrder']->UUttitle);
		$money=$orderInfo['totalPrice']/100;
        $lid = (string)$orderInfo['mainOrder']->UUlid;
        $data = array(
            'WIDout_trade_no'=> $orderid ,// 商户订单号
            'WIDsubject'=>$title,         // 订单名称
            'WIDtotal_fee'=>$money,       // 付款金额
            'WIDshow_url'=>$payArr['show_url'].'?lid='.$lid,
            'WIDbody'=>'会员购买产品'.$title,
            'return_url'=>$payArr['return_url'],
            'notify_url'=>$payArr['notify_url'],
            'buyid'=>(string)$orderInfo['mainOrder']->UUaid // 分销商 ID 
        );
		$this->make_post_c($data,$payArr['pay_url']);
	}
    
    /**
	 *未支付订单支付函数.
	 *将处理订单的分润数据，并跳的支付宝支付
	 */
	public function alipay_cst($orderid, $title, $money,$mid,$pay=array()){
    
        $script_uri = substr($_SERVER['SCRIPT_URI'],0,strrpos($_SERVER['SCRIPT_URI'],'/'));
        $payArr = array(
            'pay_url'=>'',
            'show_url'=>'',// 商品展示地址
            'return_url'=>$script_uri.'/gpay_suc.html',// 支付成功显示页面
            'notify_url'=>$script_uri.'/alipay/ali_order/notify_url_dev.php',// 回调地址
        );
        $payArr = array_merge($payArr,$pay);
        $data = array(
            'WIDout_trade_no'=> $orderid ,//商户订单号
            'WIDsubject'=>$title,    // 订单名称
            'WIDtotal_fee'=>$money, // 付款金额
            'WIDshow_url'=>'',
            'WIDbody'=>'会员购买产品'.$title,
            'return_url'=>$payArr['return_url'],
            'notify_url'=>$payArr['notify_url'],
            'buyid'=>$mid // 分销商 ID 
        );
		$this->make_post_c($data,$payArr['pay_url']);
	}
    
    /**
	 *未支付订单支付提交函数.   C 端用户
	 *@uses OrderRecord::alipay
	 */
    public static function make_post_c($data,$pay_addr=null){
        $post_data = $data;
        $script_uri = substr($_SERVER['SCRIPT_URI'],0,strrpos($_SERVER['SCRIPT_URI'],'/'));
        $url=($pay_addr) ? $pay_addr:$script_uri.'/alipay/alipay_dev.php'; 
        $post_data = http_build_query($post_data);
        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_POST, 1); 
        curl_setopt($ch, CURLOPT_HEADER, 0); 
        curl_setopt($ch, CURLOPT_URL,$url); 
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,0);
        return curl_exec($ch);
    }

}
?>